import { defineStore } from 'pinia';
import { Icon } from '@/enums/icon';

export const useSongStore = defineStore('song', {
  state: () => ({
    /** 音乐信息 */
    songId: "",
    songTitle: "",
    songUrl: "",
    songPic: `/img/songPic/tubiao.jpg`,
    singerName: "",
    lyric: [],

    /** 音乐播放信息 */
    isPlay: false,
    playBtnIcon: Icon.BOFANG,
    volume: 0,
    duration: 0,
    curTime: 0,
    changeTime: 0,
    autoNext: true,

    /** 音乐列表信息 */
    currentPlayList: [],
    songDetails: null,
    currentPlayIndex: -1,
  }),
  actions: {
    setSongId(songId) {
      this.songId = songId;
    },
    setSongTitle(songTitle) {
      this.songTitle = songTitle;
    },
    setSongUrl(songUrl) {
      this.songUrl = songUrl;
    },
    setSongPic(songPic) {
      this.songPic = songPic;
    },
    setSingerName(singerName) {
      this.singerName = singerName;
    },
    setAutoNext(autoNext) {
      this.autoNext = autoNext;
    },
    setLyric(lyric) {
      this.lyric = lyric;
    },
    setIsPlay(isPlay) {
      this.isPlay = isPlay;
    },
    setPlayBtnIcon(playBtnIcon) {
      this.playBtnIcon = playBtnIcon;
    },
    setVolume(volume) {
      this.volume = volume;
    },
    setDuration(duration) {
      this.duration = duration;
    },
    setCurTime(curTime) {
      this.curTime = curTime;
    },
    setChangeTime(changeTime) {
      this.changeTime = changeTime;
    },
    setCurrentPlayList(currentPlayList) {
      this.currentPlayList = currentPlayList;
    },
    setSongDetails(songDetails) {
      this.songDetails = songDetails;
    },
    setCurrentPlayIndex(currentPlayIndex) {
      this.currentPlayIndex = currentPlayIndex;
    },
    
    playMusic({ id, url, pic, index, songTitle, singerName, lyric, currentSongList }) {
      this.songId = id;
      this.songUrl = url;
      this.songPic = pic;
      this.currentPlayIndex = index;
      this.songTitle = songTitle;
      this.singerName = singerName;
      this.lyric = lyric;
      this.currentPlayList = currentSongList;
    }
  }
});
